package com.awangyh.jdk8.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

/**
 * Created by admin on 2017/4/11.
 */
public class ManagerDemo {

    public static void main(String[] args) throws IOException {

        Document document = Jsoup.connect("http://gs.amac.org.cn/amac-infodisc/res/pof/manager/101000005092.html").get();

        String integrityInfo = getText(document, "body > div > div.g-body > div > table > tbody > tr:nth-child(1) > td.td-content");

        // 组织机构代码
        String jgNumber = getText(document, "body > div > div.g-body > div > table > tbody > tr:nth-child(6) > td.td-content");
        // 注册资本(万元)
        String registeCapital = getText(document, "body > div > div.g-body > div > table > tbody > tr:nth-child(10) > td:nth-child(2)");
        // 员工人数
        String employees = getText(document, "body > div > div.g-body > div > table > tbody > tr:nth-child(13) > td:nth-child(2)");
        // 机构网址
        String webSite = getText(document, "body > div > div.g-body > div > table > tbody > tr:nth-child(13) > td:nth-child(4) > a");
        // 特别提示信息
        String speTips = getText(document, "#specialInfos");
        // 登记时间
        String registerDate = getText(document, "body > div > div.g-body > div > table > tbody > tr:nth-child(7) > td:nth-child(2)");
        // 成立时间
        String establishDate = getText(document, "body > div > div.g-body > div > table > tbody > tr:nth-child(7) > td:nth-child(4)");

        System.out.println("机构诚信信息:" + integrityInfo);
        for (String s : IntegrityType.selectIntegrityType(integrityInfo)) {
            System.out.println("type:" + s);
        }
        System.out.println("组织机构代码:" + jgNumber);
        System.out.println("注册资本(万元):" + registeCapital);
        System.out.println("员工人数:" + employees);
        System.out.println("机构网址:" + webSite);
        System.out.println("特别提示信息:" + speTips);
        System.out.println("登记时间:" + registerDate);
        System.out.println("成立时间:" + establishDate);


    }


    public static String getText( Document doc, String selectPath ) {
        Elements elements=doc.select( selectPath );

        if( elements.size() > 0 ) {
            return elements.get( 0 ).text().trim();
        }
        return null;
    }

    public static Document getDocument(File file, String encoding ) throws IOException {
        return Jsoup.parse( file, encoding );
    }
}
